package o;

import android.content.Context;
import android.net.Uri;
import androidx.annotation.Nullable;
import com.google.android.exoplayer2.upstream.AssetDataSource;
import com.google.android.exoplayer2.upstream.ContentDataSource;
import com.google.android.exoplayer2.upstream.DataSpec;
import com.google.android.exoplayer2.upstream.FileDataSource;
import com.google.android.exoplayer2.upstream.RawResourceDataSource;
import com.huawei.hms.common.data.DataBufferSafeParcelable;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

public final class alk implements alj {
    @Nullable
    private alj ʻ;
    @Nullable
    private alj ʼ;
    @Nullable
    private alj ʽ;
    private final Context ˊ;
    @Nullable
    private alj ˋ;
    private final alj ˎ;
    private final List<alx> ˏ = new ArrayList();
    @Nullable
    private alj ॱ;
    @Nullable
    private alj ॱॱ;
    @Nullable
    private alj ᐝ;

    public alk(Context context, alj o_alj) {
        this.ˊ = context.getApplicationContext();
        this.ˎ = (alj) amm.ॱ(o_alj);
    }

    public void ॱ(alx o_alx) {
        this.ˎ.ॱ(o_alx);
        this.ˏ.add(o_alx);
        ˏ(this.ˋ, o_alx);
        ˏ(this.ॱ, o_alx);
        ˏ(this.ʼ, o_alx);
        ˏ(this.ॱॱ, o_alx);
        ˏ(this.ʽ, o_alx);
        ˏ(this.ʻ, o_alx);
    }

    public long ˋ(DataSpec dataSpec) throws IOException {
        amm.ˏ(this.ᐝ == null);
        String scheme = dataSpec.ˎ.getScheme();
        if (anr.ˏ(dataSpec.ˎ)) {
            if (dataSpec.ˎ.getPath().startsWith("/android_asset/")) {
                this.ᐝ = ˋ();
            } else {
                this.ᐝ = ˏ();
            }
        } else if ("asset".equals(scheme)) {
            this.ᐝ = ˋ();
        } else if ("content".equals(scheme)) {
            this.ᐝ = ॱॱ();
        } else if ("rtmp".equals(scheme)) {
            this.ᐝ = ʽ();
        } else if (DataBufferSafeParcelable.DATA_FIELD.equals(scheme)) {
            this.ᐝ = ᐝ();
        } else if ("rawresource".equals(scheme)) {
            this.ᐝ = ʼ();
        } else {
            this.ᐝ = this.ˎ;
        }
        return this.ᐝ.ˋ(dataSpec);
    }

    public int ˋ(byte[] bArr, int i, int i2) throws IOException {
        return ((alj) amm.ॱ(this.ᐝ)).ˋ(bArr, i, i2);
    }

    @Nullable
    public Uri ˊ() {
        return this.ᐝ == null ? null : this.ᐝ.ˊ();
    }

    public Map<String, List<String>> ˎ() {
        return this.ᐝ == null ? Collections.emptyMap() : this.ᐝ.ˎ();
    }

    public void ॱ() throws IOException {
        if (this.ᐝ != null) {
            try {
                this.ᐝ.ॱ();
            } finally {
                this.ᐝ = null;
            }
        }
    }

    private alj ˏ() {
        if (this.ˋ == null) {
            this.ˋ = new FileDataSource();
            ˋ(this.ˋ);
        }
        return this.ˋ;
    }

    private alj ˋ() {
        if (this.ॱ == null) {
            this.ॱ = new AssetDataSource(this.ˊ);
            ˋ(this.ॱ);
        }
        return this.ॱ;
    }

    private alj ॱॱ() {
        if (this.ʼ == null) {
            this.ʼ = new ContentDataSource(this.ˊ);
            ˋ(this.ʼ);
        }
        return this.ʼ;
    }

    private alj ʽ() {
        if (this.ॱॱ == null) {
            try {
                this.ॱॱ = (alj) Class.forName("com.google.android.exoplayer2.ext.rtmp.RtmpDataSource").getConstructor(new Class[0]).newInstance(new Object[0]);
                ˋ(this.ॱॱ);
            } catch (ClassNotFoundException e) {
                amz.ˏ("DefaultDataSource", "Attempting to play RTMP stream without depending on the RTMP extension");
            } catch (Throwable e2) {
                throw new RuntimeException("Error instantiating RTMP extension", e2);
            }
            if (this.ॱॱ == null) {
                this.ॱॱ = this.ˎ;
            }
        }
        return this.ॱॱ;
    }

    private alj ᐝ() {
        if (this.ʽ == null) {
            this.ʽ = new alg();
            ˋ(this.ʽ);
        }
        return this.ʽ;
    }

    private alj ʼ() {
        if (this.ʻ == null) {
            this.ʻ = new RawResourceDataSource(this.ˊ);
            ˋ(this.ʻ);
        }
        return this.ʻ;
    }

    private void ˋ(alj o_alj) {
        for (int i = 0; i < this.ˏ.size(); i++) {
            o_alj.ॱ((alx) this.ˏ.get(i));
        }
    }

    private void ˏ(@Nullable alj o_alj, alx o_alx) {
        if (o_alj != null) {
            o_alj.ॱ(o_alx);
        }
    }
}
